(function() {

    var $u = juliet.using({ array : 'juliet.core.array-0.1' });

    var uriParserObject = {

        // -------------------------------------------------------
        // -                        LOGIC                        -
        // -------------------------------------------------------

        _parseQueryParams : function() {
            var uri = decodeURIComponent(window.location.search.replace(/\+/g, ' '));

            uri = uri.replace('?', '');

            var
            uriParts = uri.split('&'),
            params = {}, i;

            for (i = 0; i < uriParts.length; ++i) {
                var currentUriPart = uriParts[i];

                if (currentUriPart.indexOf('=') == -1) continue;

                var paramParts = currentUriPart.split('=');

                params[paramParts[0]] = paramParts[1];
            }

            return params;
        },

        _parseHashParams : function() {
            var hash = window.location.hash.substr(1);

            if (hash.length == 0) {
                return { };
            }

            var
            hashArray = hash.split('&'),
            params = { };

            $u('array').each(hashArray, function(item) {
                var paramParts = item.split('=');
                params[paramParts[0]] = paramParts[1];
            });

            return params;
        },

        //
        // API
        //

        parse : function() {
            return {
                query : this._parseQueryParams(),
                hash : this._parseHashParams()
            }
        }

    };

    juliet.registerModule('juliet.core', 'uriParser', uriParserObject);

})();
